<template>
	<view class="pages">
		<!-- 头部 -->
		<pageHeader @getIndexData="getIndexData"/>
		
		<view class="content">
			<view class="back" style="width: 40%;"
			@tap.stop="$tools.jump('/pages/index/manage')">
				<image src="@/static/public/icon-back.png" mode=""></image>
				返回
			</view>
			<view class="topBox">
				<view class="topBox-info boxBg boxBg--00">
					<view class="tipsBox">
						<view class="tipsBox-left">
							<view class="title">访问域名</view>
						</view>
					</view>
					<view class="tableTopBox">
						<view class="tableTopBox-header">
							<view class="title">编号</view>
							<view class="title">域名</view>
							<view class="title title--01">访问次数</view>
							<view class="title title--01">拦截次数</view>
							<view class="title">创建时间</view>
						</view>
						<view class="tableTopBox-list">
							<!-- <scroll-view scroll-y="true" class="scrollHeight"> -->
								<view class="tableTopBox-list__item" v-for="(item,index) in userDomain" :key="index"
								v-if="userDomain.length != 0">
									<view class="label">{{ index+1 }}</view>
									<view class="label label--copy" @tap.stop="$tools.copy(item.domain_url)">{{ item.domain_url }}</view>
									<view class="label label--01">{{ item.access_count }}</view>
									<view class="label label--01">{{ item.intercept_count }}</view>
									<view class="label">{{ item.cre_date }}</view>
								</view>
								<view class="initNoData" v-if="userDomain.length == 0">暂无数据...</view>
							<!-- </scroll-view> -->
						</view>
					</view>
				</view>
				<view class="topBox-info boxBg boxBg--0">
					<view class="tipsBox">
						<view class="tipsBox-left">
							<view class="title">放行国家</view>
						</view>
						<view class="tipsBox-right">
							<view class="searchBox">
								<image class="search" src="@/static/public/search.png" mode=""></image>
								<input type="text" placeholder="搜索名称" placeholder-class="inputSearch" v-model="searchVal" />
							</view>
							<view class="btn" @tap.stop="search()">搜索</view>
						</view>
					</view>
					<view class="tableTopBox">
						<view class="tableTopBox-header">
							<view class="title">编号</view>
							<view class="title">编码</view>
							<view class="title">名称</view>
							<view class="title">状态</view>
						</view>
						<view class="tableTopBox-list" v-if="searchFlag == false">
							<view class="tableTopBox-list__item" v-for="(item,index) in userCountry" :key="index" 
							v-if="userDomain.length != 0">
								<view class="label">{{ index+1 }}</view>
								<view class="label">{{ item.code }}</view>
								<view class="label">{{ item.name }}</view>
								<view class="label" @tap.stop="setUserCountry(item)">
									<image v-if="item.status == 0" class="check" src="@/static/public/check.png" mode=""></image>
									<image v-else class="check" src="@/static/public/check--active.png" mode=""></image>
								</view>
							</view>
							<view class="initNoData" v-if="userDomain.length == 0">暂无数据...</view>
						</view>
						<view class="tableTopBox-list" v-else>
							<view class="tableTopBox-list__item" v-for="(item,index) in checkObjList" :key="index" 
							v-if="checkObjList.length > 0">
								<view class="label">{{ index+1 }}</view>
								<view class="label">{{ item.code }}</view>
								<view class="label">{{ item.name }}</view>
								<view class="label" @tap.stop="setUserCountry(item)">
									<image v-if="item.status == 0" class="check" src="@/static/public/check.png" mode=""></image>
									<image v-else class="check" src="@/static/public/check--active.png" mode=""></image>
								</view>
							</view>
							<view class="initNoData" v-if="checkObjList.length == 0">暂无数据...</view>
						</view>
					</view>
				</view>
			</view>
			
			<!-- 白名单-->
			<view class="boxBg boxBg--1">
				<view class="tipsBox">
					<view class="tipsBox-left">
						<view class="title">放行白名单</view>
					</view>
					<view class="tipsBox-right">
						<view class="linkBox">
							<view class="label">添加ip</view>
							<view class="inputBox">
								<input type="text" placeholder="请输入ip" placeholder-class="inputLink" v-model="ipVal" />
							</view>
						</view>
						<view class="btn" @tap.stop="addIp()">添加</view>
					</view>
				</view>
				<view class="tableTopBox tableTopBox--1">
					<view class="tableTopBox-header">
						<view class="title">编号</view>
						<view class="title">ip</view>
						<view class="title">状态</view>
						<view class="title title--1">操作</view>
					</view>
					<view class="tableTopBox-list tableTopBox-list--1" v-if="isShowUserIP == true">
						<view class="tableTopBox-list__item" v-for="(item,index) in whiteIpList" :key="index" 
						 v-if="whiteIpList.length > 0">
							<view class="label">{{ item.id }}</view>
							<view class="label">{{ item.ip }}</view>
							<view class="label">{{ item.cre_date }}</view>
							<view class="label label--1" >
								<image @tap.stop="deleteIP(item,index)" class="del" src="@/static/public/delete.png" mode=""></image>
							</view>
						</view>
						<view class="initNoData" v-if="whiteIpList.length == 0">暂无数据...</view>
					</view>
				</view>
			</view>
			
			<!-- 中间  链接配置-->
			<view class="boxBg boxBg--1">
				<view class="tipsBox">
					<view class="tipsBox-left">
						<view class="title">链接配置</view>
					</view>
					<view class="tipsBox-right">
						<view class="linkBox">
							<view class="label">新增跳转链接</view>
							<view class="inputBox">
								<input type="text" placeholder="请输入链接" placeholder-class="inputLink" v-model="link" />
							</view>
						</view>
						<view class="linkBox">
							<view class="label">次数</view>
							<view class="inputBox">
								<input type="text" placeholder="请输入次数" placeholder-class="inputLink" v-model="num" />
							</view>
						</view>
						<view class="btn" @tap.stop="add()">新增</view>
					</view>
				</view>
				<view class="tableTopBox tableTopBox--1">
					<view class="tableTopBox-header">
						<view class="title">编号</view>
						<view class="title">链接</view>
						<view class="title title--2">排序</view>
						<view class="title title--2">次数</view>
						<view class="title title--1">访问次数</view>
						<view class="title title--2">访问IP次数</view>
						<view class="title title--1">状态</view>
						<view class="title">最后活跃时间</view>
						<view class="title title--1">操作</view>
					</view>
					<view class="tableTopBox-list tableTopBox-list--1" v-if="isShowUserUrl == true">
						<view class="tableTopBox-list__item" v-for="(item,index) in userUrlList" :key="index" 
						 v-if="userUrlList.length > 0">
							<view class="label">{{ item.id }}</view>
							<view class="label">{{ item.url }}</view>
							<view class="label label--flexBox">
								<view class="imgBox" @tap.stop="reduceNun('rank',item.rank,item)">
									<image src="@/static/reduce.png" mode=""></image>
								</view>
								<input type="number" v-model="item.rank" @blur="inputRankBlur($event,item)"/>
								<view class="imgBox" @tap.stop="addNun('rank',item.rank,item)">
									<image src="@/static/add.png" mode=""></image>
								</view>
							</view>
							<view class="label label--flexBox">
								<view class="imgBox" @tap.stop="reduceNun('num',item.num,item)">
									<image src="@/static/reduce.png" mode=""></image>
								</view>
								<input type="number" v-model="item.num" @blur="inputNumBlur($event,item)"/>
								<view class="imgBox" @tap.stop="addNun('num',item.num,item)">
									<image src="@/static/add.png" mode=""></image>
								</view>
							</view>
							<view class="label label--1">{{ item.access_count }}</view>
							<view class="label label--2">{{ item.ip_count ? item.ip_count : 0 }}</view>
							<view class="label label--1" @tap.stop="setUserUrl(item)">
								<image v-if="item.status == 0" class="check" src="@/static/public/check.png" mode=""></image>
								<image v-else class="check" src="@/static/public/check--active.png" mode=""></image>
							</view>
							<view class="label">{{ item.up_date }}</view>
							<view class="label label--1" >
								<image @tap.stop="deleteLink(item,index)" class="del" src="@/static/public/delete.png" mode=""></image>
							</view>
						</view>
						<view class="initNoData" v-if="userUrlList.length == 0">暂无数据...</view>
					</view>
				</view>
			</view>
			
			<!-- 中面  链接 -->
			<view class="boxBg boxBg--1">
				<view class="tipsBox">
					<view class="tipsBox-left">
						<view class="title">链接生成</view>
					</view>
				</view>
				<view class="checkBox">
					<view class="checkBox-list">
						<view class="checkBox-list__item">
							<view class="info">平台：</view>
							<uni-data-select v-model="platformVal" :localdata="platformList" @change="platformChange"></uni-data-select>
						</view>
						<view class="checkBox-list__item">
							<view class="info">国家/电话号码：</view>
							<view class="inputInfo inputInfo--two">
								<input type="number" placeholder="国家区号" placeholder-class="inputStyle" v-model="countryCode" />
								<input type="number" placeholder="请输入您的手机号" placeholder-class="inputStyle" v-model="countryPhone" />
							</view>
						</view>
						<view class="checkBox-list__item checkBox-list__item--width100">
							<view class="info info--white12">发送内容：</view>
							<view class="inputInfo inputInfo--white87">
								<input type="text" placeholder="请输入发送内容" placeholder-class="inputStyle" v-model="sendContent" />
							</view>
						</view>
					</view>
					<view class="checkBox-btnBox">
						<view class="checkBox-btn" @tap.stop="countryAdd()">新增</view>
					</view>
				</view>
				<view class="tableTopBox tableTopBox--noHeight">
					<view class="tableTopBox-header">
						<view class="title title--1">编号</view>
						<view class="title">链接</view>
						<view class="title title--1">操作</view>
					</view>
					<view class="tableTopBox-list">
						<view class="tableTopBox-list__item" v-for="(item,index) in thirdPlatformsList" :key="index" 
						v-if="thirdPlatformsList.length > 0">
							<view class="label label--1">{{ item.id }}</view>
							<view class="label label--auto" @tap.stop="$tools.copy(item.url)">{{ item.url }}</view>
							<view class="label label--1" >
								<image @tap.stop="deleteCountry(item,index)" class="del" src="@/static/public/delete.png" mode=""></image>
							</view>
						</view>
						<view class="initNoData" v-if="thirdPlatformsList.length == 0">暂无数据...</view>
					</view>
				</view>
			</view>
			
			<!-- 下面  链接 -->
			<view class="boxBg boxBg--1">
				<view class="tipsBox">
					<view class="tipsBox-left">
						<view class="title">链接日志</view>
					</view>
				</view>
				<view class="checkBox">
					<view class="checkBox-list">
						<view class="checkBox-list__item">
							<view class="info">时间：</view>
							<!-- <view class="inputInfo">
								<input type="text" placeholder="请输入时间段(YYYY-MM-DD)" placeholder-class="inputStyle" v-model="timeText" />
							</view> -->
							<uni-datetime-picker v-model="range" type="daterange" @maskClick="maskClick" />
						</view>
						<view class="checkBox-list__item">
							<view class="info">ip：</view>
							<view class="inputInfo">
								<input type="text" placeholder="请输入ip" placeholder-class="inputStyle" v-model="ipText" />
							</view>
						</view>
						<view class="checkBox-list__item">
							<view class="info">访问域名：</view>
							<view class="inputInfo">
								<input type="text" placeholder="请输入访问域名" placeholder-class="inputStyle" v-model="linkText" />
							</view>
						</view>
						<view class="checkBox-list__item">
							<view class="info">跳转域名：</view>
							<view class="inputInfo">
								<input type="text" placeholder="请输入跳转域名" placeholder-class="inputStyle" v-model="urlText" />
							</view>
						</view>
					</view>
					<view class="checkBox-btnBox">
						<view class="checkBox-btn checkBox-btn--mt" @tap.stop="reset()">重置</view>
						<view class="checkBox-btn" @tap.stop="check()">查询</view>
					</view>
				</view>
				<view class="tableTopBox tableTopBox--noHeight">
					<view class="tableTopBox-header">
						<!-- <view class="title title--2">时间</view> -->
						<view class="title">ip</view>
						<view class="title">访问域名</view>
						<view class="title">跳转链接</view>
						<view class="title">时间</view>
					</view>
					<view class="tableTopBox-list tableTopBox-list--noHeight" v-if="isShowPage">
						<view class="tableTopBox-list__item" v-for="(item,index) in recordList" :key="index" 
						 v-if="recordList.length > 0">
							<view class="label label--2" @tap.stop="$tools.copy(item.ip)">{{ item.ip }}</view>
							<view class="label" @tap.stop="$tools.copy(item.req_url)">{{ item.req_url }}</view>
							<view class="label" @tap.stop="$tools.copy(item.rep_url)">{{ item.rep_url }}</view>
							<view class="label" @tap.stop="$tools.copy(item.cre_date)">{{ item.cre_date }}</view>
						</view>
						<view class="initNoData" v-if="recordList.length == 0">暂无数据...</view>
					</view>
				</view>
				<!-- 分页 -->
				<view class="pagesBox">
					<view class="pagesBox-box">
						<page-pagination :total="page.total" :pageSize="page.pageSize" :currentPage="page.currentPage"
							:showBorder="false" :numAround="true" :btnText="true" 
							@change="change">
							<view class="pagesBox-item">
								<view class="totalNum">共 {{page.total}} 条</view>
								<view class="totalNum">前往	<!-- page.currentPage -->
									<input type="number" v-model="goToPage" @blur="inputBlur()"/>
								页</view>
							</view>
						</page-pagination>
					</view>
				</view>
			</view>
			
		</view>
		
		<!-- 底部 -->
		<pageFooter />
	</view>
</template>

<script>
	// import uniDatetimePicker from '@/components/uni-datetime-picker/uni-datetime-picker'
	import webUrl from '@/common/js/url.js';
	import pagePagination from '@/components/page-pagination.vue';
	import uniDataSelect from '@/components/uni-data-select/uni-data-select.vue';
	export default {
		components:{
			pagePagination,uniDataSelect
		},
		data() {
			return {
				searchVal: '',
				link: '',
				num: '',
				timeText: '',
				ipText: '',
				linkText: '',
				urlText: '',
				page: {
					total: 0,
					pageSize: 5,
					currentPage: 1
				},
				goToPage: 1,
				toggle: true,
				isLogin: false,
				socketOpen: false,
				token: '',
				userDomain: [],
				isShowUserCountry: false,
				userCountry: [],
				checkObjList: [],
				searchFlag: false,
				isShowUserUrl: false,
				userUrlList: [],
				isShowPage: false,
				recordList: [],
				times: null,
				timeNum: 5,
				socketTimer: null,
				range: [],
				datetimerange: [],
				start: Date.now() - 1000000000,
				end: Date.now() + 1000000000,
				ipVal: '',
				isShowUserIP: false,
				platformVal: '',
				platformList: [
					{ value: '01', text: "Whatsapp" },
				],
				countryCode: '',
				countryPhone: '',
				sendContent: '',
				thirdPlatformsList: [],
				sys_domain_id: '',
			}
		},
		watch: {
			range(newval) {
				console.log('范围选:', this.range);
			},
		},
		onBackPress() {
			if(this.times) {
				clearInterval(this.times);
				clearTimeout(this.times);  
				this.times = null; 
			}  
		},
		onHide() {
			if(this.times) {  
				clearInterval(this.times);
				clearTimeout(this.times);  
				this.times = null; 
			}  
		},
		onUnload() {
			if(this.times) {  //在页面卸载时清除定时器有时会清除不了，可在页面跳转时清除
				clearInterval(this.times);
				clearTimeout(this.times);  
				this.times = null;  
			}  
		},
		onLoad(options) {
			let that = this;
			that.sys_domain_id = options.value1;
			// console.log("sys_domain_id",this.sys_domain_id);
			that.isLogin = uni.getStorageSync('token') != '';
			console.log("that.isLogin:",that.isLogin);
			if(that.isLogin){
				that.init();
			}
			this.token = uni.getStorageSync('token');
			this.socketUrl = webUrl.websocketUrl + '/websocket/'+ this.token;
			// console.log("socketUrl",this.socketUrl);
		},
		onShow() {
			let that = this;
			if(that.isLogin){
				// that.initSocket();
				that.times = setInterval(() => {
					that.timeNum -- ;
				  if (that.timeNum == 0) {
					that.getUserUrl();
					that.getUserRecord();
					// clearTimeout(that.times);
					that.timeNum = 5;  
					return;
				  }
				}, 1000);
			}
		},
		methods: {
			init(){
				// this.userDomain = [];
				// this.isShowUserCountry = false;
				// this.userCountry = [];
				this.isShowUserUrl = false;
				this.userUrlList = [];
				this.isShowPage = false;
				this.recordList = [];
				this.getUserDomain();
				this.getUserCountry();
				this.getUserUrl();
				this.getUserRecord();
				// this.startHeartbeat();
				this.getUserWhiteIp();
				this.thirdPlatformsList = [];
				this.getThirdPlatforms();
			},
			// 删除 链接配置
			deleteCountry(item,index){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除选中的链接配置???',
					success: function (res) {
						if (res.confirm) {
							var data = {};
							data['id'] = item.id;
							data['sys_domain_id'] = that.sys_domain_id;
							that.$Ajax('/api/user/info/delThirdPlatforms',
							data,
							res => {
									if (res.success) {
										that.$tools.toastSuccess('删除成功');
										that.thirdPlatformsList.splice(index, 1);
										// this.thirdPlatformsList = [];
										// this.getThirdPlatforms();
									}else{
								this.$tools.toast(res.msg);
							}
								}
							)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 新增 中间链接
			countryAdd(){
				if (this.platformVal == '' ) {
					return this.$tools.toast('请选择平台');
				}
				if (this.countryCode == '' ) {
					return this.$tools.toast('国家区号');
				}
				if (this.countryPhone == '' ) {
					return this.$tools.toast('请输入您的手机号');
				}
				// if (this.countryPhone.length!=11 || !/^((1[0-9])+\d{9})$/.test(this.countryPhone)){
				// 	return this.$tools.toast('请输入正确的手机号码！！！');
				// }
				if (this.sendContent == '' ) {
					return this.$tools.toast('请输入发送内容');
				}
				if(this.toggle){
					this.toggle = false;
					var data = {};
					data['type'] = this.platformVal;
					data['national_code'] = this.countryCode;
					data['tel'] = this.countryPhone;
					data['text'] = this.sendContent;
					data['sys_domain_id'] = this.sys_domain_id;
					// console.log("data：",data);
					this.$Ajax('/api/user/info/addThirdPlatforms',data,res => {
							this.toggle = true;
							if (res.success) {
								this.$tools.toast("新增成功");
								this.platformVal = '';
								this.countryCode = '';
								this.countryPhone = '';
								this.sendContent = '';
								this.thirdPlatformsList = [];
								this.getThirdPlatforms();
							} else {
								this.$tools.toast(res.msg);
							}
						},err =>{
							this.toggle = true;
						}
					);
				}
			},
			// 查询中间链接
			getThirdPlatforms(){
				var data = {};
				data['sys_domain_id'] = this.sys_domain_id;
				this.$Ajax('/api/user/info/getThirdPlatforms',
				data,
				res => {
						if (res.success) {
							this.thirdPlatformsList = res.data.thirdPlatformsList;
						}else{
							this.$tools.toast(res.msg);
						}
					}
				)
			},
			platformChange(e){
				console.log(e,this.platformVal);
			},
			
			// 删除 白名单
			deleteIP(item,index){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除选中的白名单???',
					success: function (res) {
						if (res.confirm) {
							var data = {};
							data['ip'] = item.ip;
							data['sys_domain_id'] = that.sys_domain_id;
							console.log("data：",data);
							that.$Ajax('/api/user/info/delUserWhiteIp',
							data,
							res => {
									if (res.success) {
										that.whiteIpList.splice(index, 1);
										that.$tools.toastSuccess('删除白名单成功');
										// this.userUrlList = [];
										// this.getUserUrl();
									}else{
										that.$tools.toast(res.msg);
									}
								}
							)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 新增 白名单
			addIp(){
				if (this.ipVal == '' ) {
					return this.$tools.toast('请输入ip');
				}
				if(this.toggle){
					this.toggle = false;
					var data = {};
					data['ip'] = this.ipVal;
					data['sys_domain_id'] = this.sys_domain_id;
					// console.log("data：",data);
					this.$Ajax('/api/user/info/addUserWhiteIp',data,res => {
							this.toggle = true;
							if (res.success) {
								this.ipVal = '';
								// this.whiteIpList = [];
								this.isShowUserIP = true;
								this.getUserWhiteIp();
								this.$tools.toast("新增成功");
							} else {
								this.$tools.toast(res.msg);
							}
						},err =>{
							this.toggle = true;
						}
					);
				}
			},
			// 查询IP白名单
			getUserWhiteIp(){
				var data = {};
				data['sys_domain_id'] = this.sys_domain_id;
				this.$Ajax('/api/user/info/getUserWhiteIp',
				data,
				res => {
						if (res.success) {
							this.isShowUserIP = true;
							this.whiteIpList = res.data.whiteIpList;
						}else{
							this.$tools.toast(res.msg);
						}
					}
				)
			},
			// 绑卡后生成域名
			getIndexData(){
				console.log("绑定了");
				this.getUserDomain();
				this.getUserCountry();
			},
			change(e) {
				this.single = e
				console.log('change事件:', this.single = e);
			},
			changeLog(e) {
				console.log('change事件:', e);
			},
			maskClick(e){
				console.log('maskClick事件:', e);
			},
			// 减少
			reduceNun(type,num,item){
				if(num > 0){
					num --;
					if(type == 'rank'){
						this.setUserUrlRank(num,item);
					}else{
						this.setUserUrlNum(num,item);
					}
				}
			},
			addNun(type,num,item){
				num ++;
				if(type == 'rank'){
					this.setUserUrlRank(num,item);
				}else{
					this.setUserUrlNum(num,item);
				}
			},
			inputRankBlur(e,item){
				// console.log("e--rank：",e.target.value);
				this.setUserUrlRank(e.target.value,item);
			},
			inputNumBlur(e,item){
				// console.log("e--num：",e.target.value);
				this.setUserUrlNum(e.target.value,item);
			},
			// 设置用户链接排序
			setUserUrlRank(num,item){
				var data = {};
				data['url_id'] = item.id;
				data['rank'] = num;
				data['sys_domain_id'] = this.sys_domain_id;
				console.log("rank---data：",data);
				this.$Ajax('/api/user/info/setUserUrlRank',data,res => {
						this.toggle = true;
						if (res.success) {
							this.$tools.toast("设置用户链接排序成功");
							this.$set(item,'rank',num);
						} else {
							this.$tools.toast(res.msg);
						}
					},err =>{
						this.toggle = true;
					}
				);
			},
			// 设置用户链接次数
			setUserUrlNum(num,item){
				var data = {};
				data['url_id'] = item.id;
				data['num'] = num;
				data['sys_domain_id'] = this.sys_domain_id;
				console.log("num---data：",data);
				this.$Ajax('/api/user/info/setUserUrlNum',data,res => {
						this.toggle = true;
						if (res.success) {
							this.$tools.toast("设置用户链接次数成功");
							this.$set(item,'num',num);
						} else {
							this.$tools.toast(res.msg);
						}
					},err =>{
						this.toggle = true;
					}
				);
			},
			// 重置
			reset(){
				this.range = [];
				this.ipText = '';
				this.linkText = '';
				this.urlText = '';
			},
			// 查询 链接
			check(){
				// if (this.timeText == '' ) {
				// 	return this.$tools.toast('请输入时间');
				// }
				// if (this.ipText == '' ) {
				// 	return this.$tools.toast('请输入ip');
				// }
				// if (this.linkText == '' ) {
				// 	return this.$tools.toast('请输入访问域名');
				// }
				// if (this.urlText == '' ) {
				// 	return this.$tools.toast('请输入跳转域名');
				// }
				if(this.toggle){
					this.toggle = false;
					this.page = {
						total: 0,
						pageSize: 5,
						currentPage: 1
					};
					this.getUserRecord();
				}
			},
			// 查询用户记录
			getUserRecord(){
				var data = {};
				data['page_size'] = this.page.pageSize;
				data['page_num'] = this.page.currentPage;
				data['begin_time'] = this.range[0] ? this.range[0] : '';
				data['end_time'] = this.range[1] ? this.range[1] : '';
				data['ip'] = this.ipText;
				data['req_url'] = this.linkText;
				data['rep_url'] = this.urlText;
				data['sys_domain_id'] = this.sys_domain_id;
				// console.log("data:",data);
				this.$Ajax('/api/user/info/getUserRecord',
				data,
				res => {
						if (res.success) {
							this.toggle = true;
							this.isShowPage = true;
							this.page.total = res.data.totalCount;
							this.recordList = res.data.userRecordList;
							// this.range = [];
							// this.ipText = '';
							// this.linkText = '';
							// this.urlText = '';
						}else{
							this.$tools.toast(res.msg);
							this.toggle = true;
						}
					}
				)
			},
			inputBlur(){
				var data = {};
				data['page_size'] = this.page.pageSize;
				data['page_num'] = Number(this.goToPage);
				data['begin_time'] = this.range[0] ? this.range[0] : '';
				data['end_time'] = this.range[1] ? this.range[1] : '';
				data['ip'] = this.ipText;
				data['req_url'] = this.linkText;
				data['rep_url'] = this.urlText;
				console.log("data:",data);
				this.$Ajax('/api/user/info/getUserRecord',
				data,
				res => {
						if (res.success) {
							this.page.currentPage = Number(this.goToPage);
							this.toggle = true;
							this.isShowPage = true;
							this.page.total = res.data.totalCount;
							this.recordList = res.data.userRecordList;
						}else{
							this.$tools.toast(res.msg);
							this.toggle = true;
						}
					}
				)
			},
			// 设置用户链接
			setUserUrl(item){
				var data = {};
				data['url_id'] = item.id;
				data['status'] = item.status == 0 ? 1 : 0;
				data['sys_domain_id'] = this.sys_domain_id;
				// console.log("data:",data);
				this.$Ajax('/api/user/info/setUserUrl',
				data,
				res => {
						if (res.success) {
							this.$tools.toast('设置成功');
							if(item.status == 0){
								var value = Number(1);
							}else{
								var value = Number(0);
							}
							console.log("value：",value);
							this.$set(item,'status',value);
						}else{
							this.$tools.toast(res.msg);
						}
					}
				)
			},
			// 删除 链接配置
			deleteLink(item,index){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除选中的链接配置???',
					success: function (res) {
						if (res.confirm) {
							var data = {};
							data['url_id'] = item.id;
							data['sys_domain_id'] = that.sys_domain_id;
							that.$Ajax('/api/user/info/delUserUrl',
							data,
							res => {
									if (res.success) {
										that.$tools.toastSuccess('删除成功');
										
										that.userUrlList.splice(index, 1);
										// this.userUrlList = [];
										// this.getUserUrl();
									}else{
								this.$tools.toast(res.msg);
							}
								}
							)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 新增 新增用户链接
			add(){
				if (this.link == '' ) {
					return this.$tools.toast('请输入链接');
				}
				if (this.num == '' ) {
					return this.$tools.toast('请输入次数');
				}
				if(this.toggle){
					this.toggle = false;
					var data = {};
					data['url'] = this.link;
					data['num'] = this.num;
					data['sys_domain_id'] = this.sys_domain_id;
					// console.log("data：",data);
					this.$Ajax('/api/user/info/addUserUrl',data,res => {
							this.toggle = true;
							if (res.success) {
								this.$tools.toast("新增成功");
								this.link = '';
								this.num = '';
								this.userUrlList = [];
								this.getUserUrl();
							} else {
								this.$tools.toast(res.msg);
							}
						},err =>{
							this.toggle = true;
						}
					);
				}
			},
			// 查询用户链接
			getUserUrl(){
				var data = {};
				data['sys_domain_id'] = this.sys_domain_id;
				this.$Ajax('/api/user/info/getUserUrl',
				data,
				res => {
						if (res.success) {
							this.isShowUserUrl = true;
							this.userUrlList = res.data.userUrlList;
						}else{
							this.$tools.toast(res.msg);
						}
					}
				)
			},
			// 搜索 访问配置
			search(){
				let that = this;
				that.checkObjList = [];
				if (that.searchVal == '' && that.searchFlag == false) {
					return that.$tools.toast('请输入搜索名称');
				}
				// 使用正则表达式进行模糊查询
				var regex = new RegExp(that.searchVal, "i");
				var result = that.userCountry.filter(function(item) {
				  return regex.test(item.name);
				});
				// console.log(result); // 输出匹配的结果
				if(result.length > 0){
					that.searchFlag = true;
					that.checkObjList = result;
				}else{
					that.$tools.toast("不存在该名称，请重新搜索");
					that.searchVal = '';
					that.searchFlag = false;
				}
				return;
				if(JSON.stringify(that.userCountry).includes(JSON.stringify(that.searchVal)) === false){
					console.log("不存在");
					that.$tools.toast("不存在该名称，请重新搜索");
					that.searchVal = '';
					that.searchFlag = false;
				}else{
					console.log("存在");
					that.userCountry.forEach((item,index) => {
						if(item.name == that.searchVal){
							that.searchFlag = true;
							that.checkObjList.push(item);
							console.log("obj",that.checkObjList);
						}
					})
				}
			},
			// 设置用户地区
			setUserCountry(item){
				var data = {};
				data['codes'] = item.code;
				data['status'] = item.status == 0 ? 1 : 0;
				data['sys_domain_id'] = this.sys_domain_id;
				console.log("data:",data);
				this.$Ajax('/api/user/info/setUserCountry',
				data,
				res => {
						if (res.success) {
							this.$tools.toast('设置成功');
							// if(item.status == 0){
							// 	var value = Number(1);
							// }else{
							// 	var value = Number(0);
							// }
							// console.log("value：",value);
							// this.$set(item,'status',value);
							this.userCountry = [];
							this.getUserCountry();
						}else{
							this.$tools.toast(res.msg);
						}
					}
				)
			},
			// 查询用户地区
			getUserCountry(){
				var data = {};
				data['sys_domain_id'] = this.sys_domain_id;
				this.$Ajax('/api/user/info/getUserCountry',
				data,
				res => {
						if (res.success) {
							this.isShowUserCountry = true;
							this.userCountry = res.data.userCountryList;
						}else{
							this.$tools.toast(res.msg);
						}
					}
				)
			},
			// 查询用户域名
			getUserDomain(){
				var data = {};
				data['sys_domain_id'] = this.sys_domain_id;
				this.$Ajax('/api/user/info/getUserDomain',
				data,
				res => {
						if (res.success) {
							this.userDomain = res.data.userDomainList;
						}else{
							this.$tools.toast(res.msg);
							}
					}
				)
			},
			// 发送心跳包
			startHeartbeat () {
				// HeartBeat 这里是和后端约定好的值，我们发送给后端，后端再把这个值返给我们
				// 目的就是让后端知道我们一直在
				const heartbeatMsg = 'HeartBeat';
				const sendHeartbeat = () => {
					if (this.socketOpen) {
						uni.sendSocketMessage({
							data: heartbeatMsg,
						}).catch(error => {
							console.log('发送心跳消息失败:', error);
							this.reconnect()
						});
					}
				};
				this.socketTimer = setInterval(sendHeartbeat, 5000); // 每5秒发送一次心跳消息
			},
			// Socket连接
			initSocket() {
				var that = this;
				uni.connectSocket({
					url: that.socketUrl,
					// header: {
					// 	'content-type': 'application/json'
					// },
				});
				uni.onSocketOpen(res => {
					this.socketOpen = true;
					console.log('WebSocket连接已打开！');
					this.startHeartbeat();
					// this.subIndexTradeMessage();
				});
				uni.onSocketMessage(res => {
					console.log("res:",res);
					if(res){
						var message = this.parseJSONorNot(res);
						message = this.parseJSONorNot(message.data);
						message = this.parseJSONorNot(message);
						// console.log(message);
						// if (message.code == 3) {
							this.setTradeData(message);
						// }
					}
				});
				uni.onSocketError(res => {
					// this.socketOpen = false;
					// this.initSocket();
					this.socketOpen = false;
					this.reconnect();
				});
				uni.onSocketClose(res => {
					console.log('WebSocket 已关闭！');
					// this.socketOpen = false;
					// this.reconnect();
					this.unSubIndexTradeMessage();
				});
			},
			setTradeData(data) {
				console.log("data<<<<",data);
				if(this.userUrlList.length > 0){
					this.userUrlList.forEach((item,index) =>{
						if(item.rank == data.rank){
							let cre_date = data.cre_date.substr(0,4)+'-'+data.cre_date.substr(4,2)+'-'+data.cre_date.substr(6,2);
							let cre_time = data.cre_time.substr(0,2)+':'+data.cre_time.substr(2,2)+':'+data.cre_time.substr(4,2);
							let times = cre_date+' '+cre_time;
							console.log("时间：",times);
							this.$set(item,'up_date',times);
						}
					})
				}
			},
			// 开始重连
			reconnect () {
				clearTimeout(this.socketTimer);
				clearInterval(this.socketTimer);
				this.socketTimer = setTimeout(() => {
					console.log('开始重连...');
					this.initSocket();
				}, 5000); // 延迟3秒后进行重连
			},
			subIndexTradeMessage() {
				var sendInfo = {};
				sendInfo.method = 'sub';
				sendInfo.type = 2;
				sendInfo.token = this.token;
				this.sendMessage(JSON.stringify(sendInfo));
			},
			unSubIndexTradeMessage() {
				var sendInfo = {};
				sendInfo.method = 'unsub';
				sendInfo.type = 2;
				sendInfo.token = this.token;
				this.sendMessage(JSON.stringify(sendInfo));
			},
			parseJSONorNot(mayBeJSON) {
				if (typeof mayBeJSON === 'string') {
					return JSON.parse(mayBeJSON);
				} else {
					return mayBeJSON;
				}
			},
			sendMessage(message) {
				if (this.socketOpen) {
					uni.sendSocketMessage({
						data: message,
					}).catch(error => {
						console.log('发送心跳消息失败:', error);
						this.reconnect()
					});
				}
			},
			// 分页
			change(currentPage, type) { // 当前页改变
				this.page.currentPage = currentPage;
				this.goToPage = currentPage;
				console.log("点击了" + type + "，当前页：" + currentPage);
				this.getUserRecord();
			},
			sizeChange(pageSize) { // 每页条数改变
				this.page.pageSize = pageSize;
				console.log("每页", pageSize, "条");
			},
			changeTotal() { // 更改总条数
				// this.page.total = 555
			},
			changeCurrentPage() { // 更改当前页
				// this.page.currentPage = 3
			}
		}
	}
</script>

<style scoped lang="scss">
	.content{
		.back{
			@include flexLeft;
			cursor: pointer;
			margin-bottom: 40rpx;
			image{
				width: 45rpx;
				height: 45rpx;
				margin-right: 12rpx;
			}
			font-size: 32rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #333333;
		}
	}
	
</style>
